#!/bin/bash

paths=("tags/1.0.0" "tags/1.0.1" "tags/1.0.2" "trunk")
file='./bench.txt'

rm -rf ${file}

for path in ${paths[@]}
do
	uri='http://localhost/europa/'$path'/'
	c=(10)
	n=(100)
	
	echo "== ${path} ==\n" >> $file

	for (( i=0; i<${#c[*]}; i++ ))
	do
		declare total=0
		
		echo "ab -c ${c[$i]} -n ${n[$i]} $uri\n\n\c" >> $file
		
		for (( ii=1; ii<=3; ii++ ))
		do
			ab -c ${c[$i]} -n ${n[$i]} $uri >> __tmp__
			
			tmp=`cat __tmp__`
			
			rps=`expr //"$tmp" : '.*Requests per second:\s*\([^\[]*\).*' | bc`
			total=`expr "$total+$rps" | bc`
			
			rm __tmp__
			
			echo "Test ${ii}  : ${rps}" >> $file
		done
		
		avg=`expr "$total/3" | bc`
		
		echo "Average : ${avg}\n\n" >> $file
	done
done
